package com.fanshe.demo06;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo01 {
    public static void main(String[] args) throws Exception {
        ClassLoader loader = Demo01.class.getClassLoader();
        InputStream rs = loader.getResourceAsStream("prop.properties");
        Properties p = new Properties();
        p.load(rs);
        rs.close();

        String className = p.getProperty("className");
        Class<?> aClass = Class.forName(className);
        Constructor<?> de = aClass.getDeclaredConstructor();
        de.setAccessible(true);
        Object o = de.newInstance();
        String fieldName = p.getProperty("fieldName");
        Field declaredField = aClass.getDeclaredField(fieldName);
        declaredField.setAccessible(true);
        declaredField.set(o, 11);
        System.out.println(o);

        Object o1 = declaredField.get(o);
        System.out.println("年龄" + o1);
        String methodName = p.getProperty("methodName");
        Method a = aClass.getDeclaredMethod(methodName);
        a.setAccessible(true);
        Object invoke = a.invoke(o);
        System.out.println(a.getName() + "方法执行的结果:" + invoke);
    }
}
